//index.js
//获取应用实例
const app = getApp();
var util = require("../../utils/util.js");

Page({
  data: {
    motto: '点点淘金',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    };
    //查询余额
    var billUrl = app.globalData.diandianBase + "/cbclient/api/oauth/fund/query";
    // this.queryMoneyLogList();
    util.http(billUrl, this.processDoubanData);
  },

  processDoubanData: function (data) {
    console(data);
  },

  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },

  //事件处理函数
  bt_recharge: function() {
    wx.navigateTo({
      url: '/pages/logss/logs'
    })
  },
  //我的账单
  myBill:function(e){
    wx.navigateTo({
      url: '/pages/my_index/my_bill/my_bill'
    })
  },
  //我的体验卷
  myExperienVoucher: function (e) {
    wx.navigateTo({
      url: '/pages/my_index/my_experienVoucher/my_experienVoucher'
    })
  },
  //我的收货地址
  myAddress: function (e) {
    wx.navigateTo({
      url: '/pages/my_index/my_address/my_address'
    })
  },
  //实名认证
  idNtify:function(e){
    wx.navigateTo({
      url: '/pages/my_index/my_idNtify/my_idNtify',
    })
  },
  //帮助中心
  helpCenter:function(e){
    wx.navigateTo({
      url: '/pages/my_index/my_helpCenter/my_helpConter',
    })
  },
  //设置
  setUp:function(e){
    wx.navigateTo({
      url: "../../pages/my_index/my_setUp/my_setUp",
    })
  },
  //分享
  shareApp: function (e) {
    wx.navigateTo({
      url: '/pages/logss/logs'
    })
  },
  //充值
  bt_infund:function(e){
    wx.navigateTo({
      url: '../../pages/my_index/my_infund/my_infund',
    })
  },
  //提现
  bt_outfund:function(e){
    wx.navigateTo({
      url: '../../pages/my_index/my_outfund/my_outfund',
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },

})
